<template>
  <div>
      <el-breadcrumb separator="/" style="height:10px;">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>系统管理</el-breadcrumb-item>
        <el-breadcrumb-item>酒店卫生管理</el-breadcrumb-item>
      </el-breadcrumb>
      <el-table
      :data="pageinfo.list"
      border
      style="width: 100%">
      <el-table-column
        prop="guest.roomnumber"
        label="房间号"
        width="200">
      </el-table-column>

      <el-table-column
        prop="guest.roomname"
        label="房间类别"
        width="200">
      </el-table-column>

      <el-table-column
        prop="guest.user.uname"
        label="用户名"
        width="180">

      </el-table-column>

      <el-table-column label="是否需要打扫" width="180">
        <template slot-scope="scope">
          {{scope.row.hstate == 1 ? '不需要打扫' : '需要打扫'}}
        </template>
      </el-table-column>

      <el-table-column label="打扫完，是否需要删除？" width="180">
        <template slot-scope="scope">
          {{scope.row.guest.user != null ? scope.row.guest.user.uname+'入住中，无需删除！' : '客人已离开，需要删除！'}}
        </template>
      </el-table-column>

     
      <el-table-column label="管理操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="success"
            @click="findOneByhid(scope.row.hid)">修改</el-button>
          <el-button
          size="mini"
          type="danger"
          @click="delhealthbyhidfn(scope.row.hid)">删除</el-button>
            <!-- <el-switch
            @change="updateHealthFn(scope.row)"
              v-model="scope.row.value1"
              active-text="需要打扫"
              inactive-text="不需要打扫">
            </el-switch> -->
        </template>
        </el-table-column>
    </el-table>
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="healthVo.pageNum"
      :page-sizes="[5, 7, 10, 15]"
      :page-size="healthVo.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="pageinfo.total">
    </el-pagination>

    <el-dialog
      title="要打扫不?"
      :visible.sync="dialogVisible"
      width="30%">
      <el-form ref="form" :model="health" label-width="120px">
        <el-form-item label="是否需要打扫">
          <el-select v-model="health.hstate" placeholder="请选择是否需要打扫">
            <el-option  label="不需要打扫" :value="1"></el-option>
            <el-option  label="需要打扫" :value="2"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="updateHealthFn">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {findAllHealthBypage,updateHealth,findOneByhid,delhealthbyhid} from '../../api'
export default {
  data() {
    return {
      pageinfo : {
          guest : {
            user : {
              uname : null
            }
        }
      }  ,
      healthVo : {
        pageNum : 1,
        pageSize : 5
      },
      dialogVisible : false,
      health : {}
    }
  },
  created() {
    this.findAll()
  },
  methods: {
    async findAll(){
      let {data:baseRefault} = await findAllHealthBypage(this.healthVo)
      this.pageinfo = baseRefault.data
      // console.info(baseRefault.data.list)
      baseRefault.data.list.forEach(async item => {
        if(item.guest.user == null){
          this.health.hid = item.hid
          this.health.rid = item.rid
          this.health.hstate = 2
          let {data:baseRefault1} = await updateHealth(this.health)
        }
      });
      // if(baseRefault.data.){}
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.commodityVo.pageNum = 1
      this.commodityVo.pageSize = val
      this.findAll()
    },
    handleCurrentChange(val) {
      this.commodityVo.pageNum = val
      console.log(`当前页: ${val}`);
      this.findAll()
    },
    async findOneByhid(hid){
      let {data:baseRefault} = await findOneByhid(hid)
      this.health = baseRefault.data
      this.dialogVisible = true
    },
    async updateHealthFn(){
      let {data:baseRefault} = await updateHealth(this.health)
      this.$message.success(baseRefault.message)
      this.dialogVisible = false
      this.findAll()
    },
    async delhealthbyhidfn(hid){
      let {data:baseRefault} = await delhealthbyhid(hid)
      this.$message.success(baseRefault.message)
      this.findAll()
    }
    
    
  },
}
</script>

<style>

</style>